<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
    <meta name="renderer" content="webkit">
    <!--国产浏览器高速模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    .
    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="${root}/css/base.css">
    <link rel="stylesheet" type="text/css" href="${root}/css/iconfont.css">
    <script type="text/javascript" src="${root}/framework/jquery-1.11.3.min.js"></script>
    <script type="application/javascript" src="${root}/jquery/jquery-form.js"></script>
    <link rel="stylesheet" type="text/css" href="${root}/layui/css/layui.css">
    <script type="text/javascript" src="${root}/layui/layui.js"></script>
    <!-- 滚动条插件 -->
    <link rel="stylesheet" type="text/css" href="${root}/css/jquery.mCustomScrollbar.css">
    <script src="${root}/framework/jquery-ui-1.10.4.min.js"></script>
    <script src="${root}/framework/jquery.mousewheel.min.js"></script>
    <script src="${root}/framework/jquery.mCustomScrollbar.min.js"></script>
    <script src="${root}/framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
    <!-- 公共样式 结束 -->

    <style>
        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            margin-left: 130px;
        }

        .layui-form {
            margin-right: 30%;
        }
    </style>

</head>

<body>
<div class="cBody">
    <form id="updateForm" name="addForm" class="layui-form" action="${root}/admin/Movie_update" method="post"
          enctype="multipart/form-data">
        <input type="hidden" name="id" value="${movie.id}" /> &nbsp;
        <div class="layui-form-item">
            <label class="layui-form-label">电影名</label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" required lay-verify="required" autocomplete="off" value="${movie.name}"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电影海报</label>
            <img width="150" src="${movie.image}">
            <input type="file" id="image" name="file" size="30"/>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">售价</label>
            <div class="layui-input-block">
                <input type="text" id="price" name="price" required lay-verify="required|number" autocomplete="off"
                       class="layui-input" value="${movie.price}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电影时长</label>
            <div class="layui-input-block">
                <input type="text" id="duration" name="duration" required lay-verify="required|number"
                       autocomplete="off" class="layui-input" value="${movie.duration}">
            </div>
        </div>
        <%--<div class="layui-form-item">--%>
            <%--<label class="layui-form-label">上映时间</label>--%>
            <%--<div class="layui-input-block">--%>
                <%--<input type="text" id="dates" name="dates" required lay-verify="required"--%>
                       <%--autocomplete="off" class="layui-input" value="${movie.dates}"  />--%>

            <%--</div>--%>
        <%--</div>--%>
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline">
                <select name="dis_id" id="dis_id" lay-filter="dis_id">
                    <option value="">地区分类</option>
                    <c:forEach var="d" items="${d_list}">
                        <option value="${d.id}">${d.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="layui-input-inline">
                <select name="type_id" id="type_id" lay-filter="type_id">
                    <option value="">类型分类</option>
                    <c:forEach var="t" items="${t_list}">
                        <option value="${t.id}">${t.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitBut" onclick="movie_update()">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


    <script>
        layui.use(['upload', 'form'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var layer = layui.layer;
            //监听提交
            form.on('submit(submitBut)', function (data) {
                return false;
            });
            form.verify({
                //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
                ZHCheck: [
                    /^[\u0391-\uFFE5]+$/
                    , '只允许输入中文'
                ]
            });
            //拖拽上传
            upload.render({
                elem: '#goodsPic',
                url: '/upload/',
                done: function (res) {
                    console.log(res)
                }
            });
        });
    </script>
    <script>
        function movie_update() {
            var name = $("#name").val();
            var image = $("#image").val();
            var price = $("#price").val();
            var duration = $("#duration").val();
//            var dates = $("#dates").val();
            var dis_id = $("#dis_id").val();
            var type_id = $("#type_id").val();
            var moviespan = $("#moviespan").html();
            if (name == null || name == "") {
                return false;
            }
            if (price == null || price == "") {
                return false;
            }
            if (duration == null || duration == "") {
                return false;
            }
//            if (dates == null || dates == "") {
//                return false;
//            }
//
            if (dis_id == null || dis_id == "") {
                alert("请选择地区");
                return false;
            }
            if (type_id == null || type_id == "") {
                alert("请选择电影类型");
                return false;
            }
            var option = {
                url: "/admin/Movie_update",
                type: "post",
                dataType: "json",
                headers: {"ClientCallMode": "ajax"},
                success: function (resp) {
                    alert(resp.message);
                    if (resp.data == 0) {
                        window.location.href = "/admin/movie_list";
                    }
                },
                error: function (resp) {
                    alert(resp.message);
                }
            };
            $("#updateForm").ajaxSubmit(option);
            return false;
        };
        // get(); //此处为上传文件的进度
    </script>
</div>
</body>

</html>